package com.xgc.book.bookserver.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xgc.book.bookserver.bean.AdBean;
import com.xgc.book.bookserver.mapper.AdMapper;
import com.xgc.book.bookserver.service.AdService;
import com.xgc.book.bookserver.util.ResultJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 广告表 服务实现类
 * </p>
 *
 * @author wrz
 * @since 2023-11-20
 */
@Service
@Transactional
public class AdServiceImpl extends ServiceImpl<AdMapper, AdBean> implements AdService {

    @Autowired
    private AdMapper adMapper;

    @Override
    public ResultJson getPage(int page, int limit, AdBean adBean) {
        IPage<AdBean> iPage = adMapper.getPage(new Page<>(page, limit), adBean);
        return ResultJson.ok(iPage);
    }

    @Override
    public ResultJson getAdList() {
        List<AdBean> list = this.list(new QueryWrapper<AdBean>()
                .eq("status", 1)
                .lt("expires_start", new Date())
                .gt("expires_end", new Date())
                .orderByDesc("order_no"));
        return ResultJson.ok(list);
    }
}
